#include<bits/stdc++.h>
#define XH(i,a,b) for(int i=a;i<b;++i)
#define XXH(i,a,b) for(int i=a-1;i>=b;--i)
#define LL long long
using namespace std;
int tmpINT; string tmpSTRING; char tmpCHAR; double tmpDOUBLE; LL tmpLONGLONG;

int main(){
	int h,w;scanf("%d%d", &h,&w);
	getchar();
	char matrix[h][w];
	XH(i , 0 , h)XH(j , 0 , w){
		scanf("%c", &matrix[i][j]);
		if(j == w-1&&i!=h-1)getchar();
	}
	int ans = 0;
	XH(i , 0 , h-1)XH(j , 1 , w-1){
		if(matrix[i][j]!=matrix[i+1][j]){
			// printf("i=%d,j=%d\n", i,j);
			++ans;
			while(matrix[i][j+1]==matrix[i][j]&&matrix[i+1][j+1]==matrix[i+1][j]){
				++j;
			}
		}
	}
	XH(j , 0 , w-1)XH(i , 1 , h-1){
		if(matrix[i][j]!=matrix[i][j+1]){
			++ans;
			// printf("i=%d,j=%d\n", i,j);
			while(matrix[i+1][j]==matrix[i][j]&&matrix[i+1][j+1]==matrix[i][j+1]){
				++i;
			}
		}
	}
	printf("%d\n", ans);
	
	return 0;
}